package org.example.spring.mapper;

import org.apache.ibatis.annotations.*;
import org.example.spring.domain.pojo.Category;

import java.util.ArrayList;

@Mapper
public interface CategoryMapper {
    @Select("SELECT * FROM categories order by category_id")
    ArrayList<Category> getAllCategory();

    @Delete("DELETE FROM categories WHERE category_name = #{categoryName}")
    void deleteCategory(String categoryName);

    @Update("update categories set category_name=#{categoryName} where category_id=#{categoryId}")
    void updateCategory(Category category);

    @Select("SELECT category_name FROM categories WHERE category_id = #{categoryId}")
    String getCategoryNameById(Integer categoryId);

    @Select("SELECT COUNT(*) FROM categories WHERE category_name = #{categoryName}")
    int getCount(String categoryName);

    @Insert("INSERT INTO categories (category_name) VALUES (#{categoryName})")
    void addCategory(String categoryName);
}
